/*
* @file    : Tja1043.c
* @author  : Larissa
* @brief   : xxx module Header file
*/

#include "Tja1043.h"
#include "Port.h"

static TJA1043_MODE_t mode = TJA1043_MODE_NORMAL;

void Tja1043_Init()
{
	Port_Tja1043GPIOInit();

	Tja1043_ToNormalMode();
}

/**
 * Normal to GO-TO-SLEEP
 * STB_N = L, EN = H
 */
void Tja1043_ToSleepMode()
{
	mode = TJA1043_MODE_GOTOSLEEP;
	Port_Clear(PORT_MODULE_TJA1043_STB_N, TJA1043_STB_N_IDX);
	Port_Set(PORT_MODULE_TJA1043_EN, TJA1043_EN_IDX);

	mode = TJA1043_MODE_SLEEP;
}

/**
 * to STANDBY
 * STB_N = L, EN = L
 */
void Tja1043_ToStandbyMode()
{
	Port_Clear(PORT_MODULE_TJA1043_STB_N, TJA1043_STB_N_IDX);
	Port_Clear(PORT_MODULE_TJA1043_EN, TJA1043_EN_IDX);
}

/**
 * switch to NORMAL
 * STB_N = H, EN = H
 */
void Tja1043_ToNormalMode()
{
	Port_Set(PORT_MODULE_TJA1043_STB_N, TJA1043_STB_N_IDX);
	Port_Set(PORT_MODULE_TJA1043_EN, TJA1043_EN_IDX);
	mode = TJA1043_MODE_NORMAL;
}

uint8_t sleep = 0;

void Tja1043_100ms()
{
	static uint32_t timer_5s_cnt = 100;
	timer_5s_cnt --;

	if(!timer_5s_cnt)
	{
		timer_5s_cnt = 50;


		/*
		if(!sleep)
		{
			sleep = 1;
			Tja1043_ToSleepMode();
		}
		else
		{
			sleep = 0;
			Tja1043_ToNormalMode();
		}
		*/
	}
}
